<template>
	<view style="">
		<view class="imgclass" >
			<view style="flex: 5;">头像</view>
			<view style="flex: 5;text-align: right;">
				<image class="imgclass-img"  :src="host+userInfo.photo"></image>
			</view>
		</view>
		<view class="lists">
			<view style="flex: 5;">昵称</view>
			<view style="flex: 5;text-align: right;">{{userInfo.name}}</view>
		</view>
		<view class="lists">
			<view style="flex: 5;">登录名</view>
			<view style="flex: 5;text-align: right;">{{userInfo.loginName}}</view>
		</view>
		<view class="lists" style="margin-top: 20rpx;">
			<view style="flex: 5;">工号</view>
			<view style="flex: 5;text-align: right;">{{userInfo.no}}</view>
		</view>
		<view class="lists">
			<view style="flex: 5;">邮箱</view>
			<view style="flex: 5;text-align: right;">{{userInfo.email}}</view>
		</view>
		<view class="lists">
			<view style="flex: 5;">电话</view>
			<view style="flex: 5;text-align: right;">{{userInfo.mobile}}</view>
		</view>
		<view class="lists" style="margin-top: 20rpx;">
			<view style="flex: 5;">公司</view>
			<view style="flex: 5;text-align: right;">{{userInfo.company.name}}</view>
		</view>
		<view class="lists">
			<view style="flex: 5;">角色</view>
			<view style="flex: 5;text-align: right;">{{userInfo.roleNames}}</view>
		</view>
		
		
		<view class="lists" style="margin-top: 20rpx;" v-if="pwdshow">
			<view style="flex: 5;">旧密码</view>
			<view style="flex: 5;text-align: right;">
				<view style="border-bottom: 1rpx solid #007AFF;position: relative;top: 46rpx;">
					<input placeholder="请输入旧密码" password="true" v-model="oldpwd"/>
				</view>
	
			</view>
		</view>
		<view class="lists" v-if="pwdshow">
			<view style="flex: 5;">新密码</view>
			<view style="flex: 5;text-align: right;">
				<view style="border-bottom: 1rpx solid #007AFF;position: relative;top: 46rpx;">
					<input placeholder="请输入新密码" password="true" v-model="newpwd"/>
				</view>
			
			</view>
		</view>
		
		<view style=" padding: 30rpx 30rpx 0 30rpx;">
	
			<button @click="butpwd" style="background-color: #0081FF;color: white;">{{pwdstart}}</button>
			
		</view>
		
		
		
		
	</view>
</template>

<script>
	let _this;
	export default {
		data() {
			return {
				userInfo:{},
				host:"",
				pwdstart:"修改密码",
				pwdshow:false,
				oldpwd:"",
				newpwd:""
			}
		},
		onLoad(){
			_this=this;
			this.getUserInfo();
		},
		methods: {
			//获取登陆用户信息
			getUserInfo:function(){
				  const value = uni.getStorageSync("JSESSIONID");
				  const val = uni.getStorageSync("pathHost");
				 _this.host=val;
				   uni.request({
				  	 url: val+"/ggcapp/sys/user/infoData"+";JSESSIONID="+value+"?__ajax=true&mobileLogin=true",
				  	 success(data) {
				
						if(data.data.success!=undefined){
							console.log("请求成功----");
								// console.log(data);
								 _this.userInfo=data.data.body.data;
						}else{
							console.log("请求失败----");
							uni.setStorageSync("loginState",false);
							uni.redirectTo({
							   url: '/pages/login/login'
							});
						}
					}
				})
			},
			butpwd(){
				if(_this.pwdstart=="修改密码"){
					_this.pwdshow=true;
					_this.pwdstart="提交";
				}else if(_this.pwdstart="提交"){
					if(_this.oldpwd.length>0&&this.newpwd.length>0 ){
						console.log(_this.oldpwd)
						console.log(_this.newpwd)
						const value = uni.getStorageSync("JSESSIONID");
						  const val = uni.getStorageSync("pathHost");
						   uni.request({
						  	 url: val+"/ggcapp//sys/user/savePwd"+";JSESSIONID="+value+"?__ajax=true&mobileLogin=true",
							 data:{
								 oldPassword:_this.oldpwd,
								 newPassword:_this.newpwd
							 },
						  	 success(data) {
						       console.log(data)
							   if(data.data.success){
								   _this.oldpwd="";
								   _this.newpwd="";
								   uni.showToast({
								       title: data.data.msg,
								       duration: 2000
								   });
								   _this.pwdshow=false;
								   _this.pwdstart="修改密码";
							   }else{
								   uni.showToast({
								       title: "修改失败",
								       duration: 2000
								   });
							   }
								
								
							}
						})
						
						
						
						
						
					}else{
						uni.showToast({
						    title: '密码不能为空',
						    duration: 2000
						});
					}
					
					
				}
				
				
			}

		}
	}
</script>

<style>
	.imgclass{
		display: flex;flex: 10;height: 140rpx;border-bottom: 1rpx solid #DCDEE2;margin-top: 10rpx;
		background-color: white;padding: 0 30rpx 0 30rpx;line-height: 140rpx;
	   
		
	}
	.imgclass-img{
			   
			   width: 100rpx;height: 100rpx;
			   border-radius: 50%;border: 1px solid #DCDEE2;position: relative;top: 20rpx;
			   
	}
	
	
	.lists{
		display: flex;flex: 10;height: 120rpx;border-bottom: 1rpx solid #DCDEE2;
		background-color: white;padding: 0 30rpx 0 30rpx;line-height: 120rpx;
	}
	
	
	

</style>
